# include <stdio.h>
# include <conio.h>
# include <iostream.h>
main()
{
int x=0,j,n,y=0,i,jum=0,bt[100],at[100],p[100],nama[100],w=0,m,z[100],max=0;

float hsl;
cout <<"__________________Program Penjadwalan FIFO (First In First Out)_________________";cout<<endl;
cout<<endl;
cout<<endl;
cout<<"Nama : 1. Rama Adli Zain  (1310511008)";                     
cout<<endl;
cout<<endl;
cout<<"Proses Penjadwalan";
cout<<endl;
cout<<endl;
cout<<"Jumlah Proses : ";
cin>>n, "%d";
cout<<endl;
for(i=0;i<n;i++)
{
cout<<"Nilai Burst Time P"<<i+1, "%s";
cout<<" : ";
cin>>bt[i], "%d";
}
cout<<endl;
cout<<"Nilai Arrival Time P1 : 0"<<endl;
at[0]=0,nama[0]=1;
for(i=1;i<n;i++)
{
cout<<"Nilai Arrival Time P"<<i+1<<" : ";
cin>>at[i];nama[i]=i+1;
}
int temp;
for(i=0;i<n;i++){
                
        for(j=0;j<n;j++){
        if(at[i]<at[j]){
                temp=at[j];
                at[j]=at[i];
                at[i]=temp;
                
                temp=nama[j];
                nama[j]=nama[i];
                nama[i]=temp;

                temp=bt[j];
                bt[j]=bt[i];
                bt[i]=temp;
        }
        }
}
cout<<endl;
cout<<"-----------------------------------------------";
cout<<endl;
cout<<"|   Nama  |  Burst time  |    Arrival Time   |";
cout<<endl;
cout<<"-----------------------------------------------";
cout<<endl;
for(i=0;i<n;i++)
{
cout<<"    P"<<nama[i], "%s";
cout<<"           "<<bt[i],     "%d";
cout<<"                "<<at[i], "%d";
cout<<endl;     
}
cout<<endl;
cout<<"----------------------------";
cout<<endl;
cout<<endl;
cout<<">>>>>>>Diagram Grant<<<<<<<<";
cout<<endl;
cout<<endl;
for(i=0;i<n;i++)
{
cout<<"------------------------------------------";
cout<<endl;
cout<<"Penjadwalan proses "<<nama[i], "%s"; 
cout<<" Dari "<<x, "%d";
cout<<" (Waktu Tunggu)";
cout<<" Ke "<<(x+bt[i]), "%d";
cout<<endl;
cout<<"------------------------------------------";
x=x+bt[i];
z[i]=x;
max=max+z[i];
cout<<endl;
}
int k;
k=at[0];
for(i=0;i<(n-1);i++)
{
        k=k+z[i]-at[i+1];
}
hsl=(float)k/n;
cout<<endl;
cout<<" Average Waiting Time : "<<hsl;

cout<<endl;
cout<<endl;
float ta;
ta=(float)max/n;
cout<<" Turn Around Time : "<<ta;
cout<<endl;
getch();
}